import axios from "axios"
import router from "../router"

export const http = axios.create({
    baseURL:"http://47.96.0.211:3001/admin/",
    headers:{
        "Content-Type": "application/json"
    }
})

// 添加请求拦截器
http.interceptors.request.use(
  function (config) {
    const token = localStorage.getItem('token')
    if(token){
        config.headers.token = token
    }
    return config;
  }, function (error) {
    // 对请求错误做些什么
    return Promise.reject(error);
  });

// 添加响应拦截器
http.interceptors.response.use(
  function (response) {
    if(response.data?.code == 10119){
      localStorage.removeItem('token');
      router.push('/login');
    }
    return response.data;
  }, function (error) {
    // 对响应错误做点什么
    return Promise.reject(error);
  }
  
  );